*Replication file 02a_Success_ordered_probit
*Article: Counterfactual Coercion: Could harsher sanctions against Russia have prevented the worst?
*Authors: Thies Niemeier, Gerald Schneider


***************************************************************
***EU***
***************************************************************

*Prepare data
use"Dataset.dta", clear
keep if sender=="EU"

* Setup
** Filter for cases of importance
keep if pot_sanctioned_countries == 1
** Set Panel Structure
xtset ccodecow year

* Independent Variables
gen ln_oil_gas_value_2014 = ln(oil_gas_value_2014+1)
gen sender_colony=0
replace sender_colony=1 if ht_colonial==2 | ht_colonial==3 | ht_colonial==6 | ht_colonial==7 | ht_colonial==8 | ht_colonial==9 | ht_colonial==10

gen sender_additional=cond(threatUS==1 | impositionUS == 1, 1, 0)
gen only_threat=cond(threatEU==1 & impositionEU == 0, 1, 0)
gen sender_trade = ln_EU_Trade_Eurostat
gen coup_dummy = coup1
replace coup_dummy = 0 if coup_dummy == 1
replace coup_dummy = 1 if coup_dummy == 2

* Variable indicating sanction onset
replace caseid=0 if caseid==.
gen sanctiononset = (caseid-l.caseid)
replace sanctiononset=1 if sanctiononset > 1 & !missing(sanctiononset)
replace sanctiononset=0 if sanctiononset < 0
replace sanctiononset=. if sanctiononset == 0 & (sanction_dyad == 1 | threat_dyad == 1)
tab sanctiononset

* include threat intensity into intensity measure
gen intensity = impositionEU_target
replace intensity=threatEU_target if missing(intensity)

* combine intensity 1-2 & 3-5, because almost no cases
*3-4,5
replace intensity=1 if intensity==1 | intensity==2 
replace intensity=2 if intensity==3 | intensity==4 
replace intensity=3 if intensity==5
replace intensity=4 if intensity==6

* Gradualism
gen gradualism = impositionEU_gradualism
replace gradualism=1 if missing(impositionEU_gradualism) & sanctiononset==1

* Ordinal success variable based on HSE score
* 6; 12
gen ordsuccess=0 if sanctiononset == 1
replace ordsuccess=1 if HSEscore == 6 | HSEscore == 9
replace ordsuccess=2 if HSEscore == 12 | HSEscore == 16

* create training and test variable
gen ordsuccess_train= ordsuccess * sanctiononset if year < 2009
gen ordsuccess_test= ordsuccess*sanctiononset if year >= 2009


** Regressions
eststo:ologit ordsuccess_train i.intensity L.v2x_polyarchy i.L.gd_ptss i.L.coup_dummy i.L.one_sided_violence i.L.conflict i.L.mid_terr_integrity L.ln_GDPpc_imputed L.sender_trade L.ln_oil_gas_value_2014 i.L.sender_colony i.L.defense_alliance i.sender_additional i.only_threat i.gradualism 

*Predictions
predict sucEU*, pr
gen sucEU=1*sucEU2 + 2*sucEU3
*drop sucEU sucEU1 sucEU2 sucEU3
gen bin_sucEU = cond(sucEU >=1.33, 2, cond(sucEU >=.66, 1, 0))
replace bin_sucEU=. if missing(sucEU)
tab ordsuccess_test bin_sucEU
tab2xl ordsuccess_test bin_sucEU using Main_Article\EU_Success_Confusion_Matrix, col(1) row(1)

* Model evaluation
* Cohen's Kappa (weighted) .28
kap ordsuccess_test bin_sucEU, wgt(w) 

* predict for different intensities
* intensity = 1
replace intensity=1 if intensity !=.

predict sucEUlow*, pr

gen sucEUlow=1*sucEUlow2 + 2*sucEUlow3 

* intensity = 2
replace intensity=2 if intensity !=.
predict sucEUmed*, pr

gen sucEUmed=1*sucEUmed2 + 2*sucEUmed3 

* intensity = 3
replace intensity=3 if intensity !=.

predict sucEUhigh*, pr
gen sucEUhigh = 1*sucEUhigh2 + 2*sucEUhigh3 

* intensity = 4
replace intensity=4 if intensity !=.

predict sucEUhigher*, pr
gen sucEUhigher = 1*sucEUhigher2 + 2*sucEUhigher3 

drop if missing(ordsuccess_test)

* Save dataset outcomes to excel. 
export excel sender year cname caseid HSEscore ordsuccess_test sucEU* using "Supplemental_Material\EU_Case_level_Success_Results", firstrow(variables) replace


***************************************************************
***US***
***************************************************************

*Prepare data
use"Dataset.dta", clear
keep if sender=="US"

* Setup
** Filter for cases of importance
keep if pot_sanctioned_countries == 1
** Panel structure
xtset ccodecow year

* Independent variables
gen ln_oil_gas_value_2014 = ln(oil_gas_value_2014+1)
gen sender_colony = US_colony
gen coup_dummy = coup1
replace coup_dummy=0 if coup1==1
replace coup_dummy=1 if coup1==2

gen sender_additional=cond(threatEU==1 | impositionEU == 1, 1, 0)
gen only_threat=cond(threatUS==1 & impositionUS == 0, 1, 0)
gen sender_trade = ln_US_Trade_COW

* Variable for sanction onset
replace caseid=0 if caseid==.
gen sanctiononset = (caseid-l.caseid)
replace sanctiononset=1 if sanctiononset > 1 & !missing(sanctiononset)
replace sanctiononset=0 if sanctiononset < 0
replace sanctiononset=. if sanctiononset == 0 & (sanction_dyad == 1 | threat_dyad == 1)
tab sanctiononset

* include threat intensity into intensity measure
gen intensity = impositionUS_target
replace intensity=threatUS_target if missing(intensity)

* combine intensity 1-2 & 3-5, because almost no cases
*3-4,5
replace intensity=1 if intensity==1 | intensity==2 
replace intensity=2 if intensity==3 | intensity==4 
replace intensity=3 if intensity==5
replace intensity=4 if intensity==6

* Gradualism
gen gradualism = impositionUS_gradualism
replace gradualism=1 if missing(impositionUS_gradualism) & sanctiononset==1

* HSE score
* 6; 12
gen ordsuccess=0 if sanctiononset == 1
replace ordsuccess=1 if HSEscore == 6 | HSEscore == 9
replace ordsuccess=2 if HSEscore == 12 | HSEscore == 16

* create training and test variable
gen ordsuccess_train= ordsuccess*sanctiononset if year < 2009
gen ordsuccess_test= ordsuccess*sanctiononset if year >= 2009


** Regressions
eststo:ologit ordsuccess_train i.intensity L.v2x_polyarchy i.L.gd_ptss i.L.one_sided_violence i.L.conflict i.L.mid_terr_integrity L.ln_GDPpc_imputed L.sender_trade L.ln_oil_gas_value_2014 i.L.defense_alliance i.sender_additional i.only_threat i.gradualism 

*Predictions
predict sucUS*, pr
gen sucUS=1*sucUS2 + 2*sucUS3
*drop sucUS sucUS1 sucUS2 sucUS3
gen bin_sucUS = cond(sucUS >=1.33, 2, cond(sucUS >=.66, 1, 0))
replace bin_sucUS=. if missing(sucUS)
tab2xl ordsuccess_test bin_sucUS using Main_Article\US_Success_Confusion_Matrix, col(1) row(1)

* Model Evaluation
* Cohen's Kappa (weighted) .24
kap ordsuccess_test bin_sucUS, wgt(w)


* predict for different intensities
* intensity = 1
replace intensity=1 if intensity !=.

predict sucUSlow*, pr

gen sucUSlow=1*sucUSlow2 + 2*sucUSlow3 

* intensity = 2
replace intensity=2 if intensity !=.
predict sucUSmed*, pr

gen sucUSmed=1*sucUSmed2 + 2*sucUSmed3 

* intensity = 3
replace intensity=3 if intensity !=.

predict sucUShigh*, pr
gen sucUShigh = 1*sucUShigh2 + 2*sucUShigh3 

* intensity = 4
replace intensity=4 if intensity !=.

predict sucUShigher*, pr
gen sucUShigher = 1*sucUShigher2 + 2*sucUShigher3 

drop if missing(ordsuccess_test)

* Save dataset outcomes to excel. 
export excel sender year cname caseid HSEscore ordsuccess_test sucUS* using "Supplemental_Material\US_Case_level_Success_Results", firstrow(variables) replace

*Output
esttab est1 est2 using Supplemental_Material\Regression_Tables\Regressions_Success.rtf, se scalars(chi2 p ll r2_p) keep(L.v2x_polyarchy 2L.gd_ptss 3L.gd_ptss 4L.gd_ptss 5L.gd_ptss 1L.coup_dummy 1L.one_sided_violence 1L.conflict 1L.mid_terr_integrity L.ln_GDPpc_imputed L.sender_trade L.ln_oil_gas_value_2014 1L.sender_colony 1L.defense_alliance 1.sender_additional 1.only_threat 2.intensity 3.intensity 4.intensity 2.gradualism 3.gradualism 4.gradualism ) order(L.v2x_polyarchy 2L.gd_ptss 3L.gd_ptss 4L.gd_ptss 5L.gd_ptss 1L.coup_dummy 1L.one_sided_violence 1L.conflict 1L.mid_terr_integrity L.ln_GDPpc_imputed L.sender_trade L.ln_oil_gas_value_2014 1L.defense_alliance 1L.sender_colony 1.only_threat 1.sender_additional 2.intensity 3.intensity 4.intensity 2.gradualism 3.gradualism 4.gradualism) label legend varlabels(L.v2x_polyarchy Dem._Index 2L.gd_ptss Pol._Terror_2 3L.gd_ptss Pol._Terror_3 4L.gd_ptss Pol._Terror_4 5L.gd_ptss Pol._Terror_5 1L.coup_dummy Mil._Coup 1L.one_sided_violence One-sided_Violence 1L.conflict Armed_Conflict 1L.mid_terr_integrity Terr._Integrity L.ln_GDPpc_imputed GDP_p.c. L.sender_trade Sender_Trade L.ln_oil_gas_value_2014 Target_Oil_Gas_Exports 1L.sender_colony Sender_Colony 1L.defense_alliance Defense_Alliance 1.sender_additional Multilateral_US/EU 1.only_threat Threat 2.intensity Intensity_2 3.intensity Intensity_3 4.intensity Intensity_4 2.gradualism Gradualism_2 3.gradualism Gradualism_3 4.gradualism Gradualism_4) mtitles("EU" "US") eqlabel(" ") wide star(* 0.10 ** 0.05 ** 0.01)
